<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;
class CertorderController extends BaseController {

    //订单列表
	public function index() {
        $data = array_filter($_GET);
        if (!empty($_GET['user_name'])) {
            $data['user_name'] = array('like',"%".trim($_GET['user_name'])."%");
        }
        unset($data['p']);
        $count = M('certorder')->alias('c')->field('c.*,u.user_id,u.user_name,u.user_phone')->join('left join midi_exam as e on c.certorder_examid = e.exam_id')->join('left join midi_user as u on e.exam_user_id = u.user_id')->where($data)->count();
        $page = getpage($count,10);
        $certorder_arr = M('certorder')->alias('c')->field('c.*,u.user_id,u.user_name,u.user_phone')->join('left join midi_exam as e on c.certorder_examid = e.exam_id')->join('left join midi_user as u on e.exam_user_id = u.user_id')->where($data)->order('certorder_id desc')->limit($page->firstRow, $page->listRows)->select();
        $this->assign('certorder_arr', $certorder_arr);
        $this->assign('page', $page->show());
        $this->display();
    }

    //订单详情
    public function order_details(){
        $data['certorder_id'] = I('get.id');
        $certorder_arr = M('certorder')->alias('c')->join('left join midi_exam as e on c.certorder_examid = e.exam_id')->join('left join midi_user as u on e.exam_user_id = u.user_id')->where($data)->find();
        $this->assign('certorder_arr',$certorder_arr);
        $this->display();
    }

    //修改订单状态
    public function order_edit(){
        if (I('post.action') == 'order_edit_action') {
            $this->order_edit_action();
            exit();
        }
        $certorder_arr = M('certorder')->where($_POST)->find();
        echo json_encode($certorder_arr);
    }

    //修改订单状态操作
    public function order_edit_action(){
        if(M('certorder')->save($_POST)){
            $this->redirect('index');
        }else{
            $this->error('修改订单失败！');
        }
    }


}